package com.bys.systemclock.view;

import android.content.Context;
import android.graphics.Path;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.bys.systemclock.R;

/**
 * 选择铃声的途径
 * @author bys
 * @since 1.0
 * @version 1.0
 */
public class SelectRemindWayPopup implements View.OnClickListener{
    private Context context;
//    铃声的方式
    private TextView remind_way1,remind_way2;
//    悬浮框
    private PopupWindow popupWindow;
    private SelectRemindWayPopupOnClickListener selectRemindWayPopupOnClickListener;
    public SelectRemindWayPopup(Context context) {
        this.context = context;
        popupWindow = new PopupWindow(context);
//        设置背景
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
//        设置宽
        popupWindow.setWidth(WindowManager.LayoutParams.MATCH_PARENT);
//        设置高
        popupWindow.setHeight(WindowManager.LayoutParams.MATCH_PARENT);
//        设置PopUpWindow的焦点，设置为true之后，PopupWindow内容区域，才可以响应点击事件
        popupWindow.setTouchable(true);
//        //点击空白处的时候让PopupWindow消失
        popupWindow.setOutsideTouchable(true);
//        设置焦点，PopupWindow弹出后，所有的触屏和物理按键都由PopupWindows 处理。
//        popupWindow.setFocusable(true);
//        设置动画
        popupWindow.setAnimationStyle(R.style.animBottom);
//        设置view布局
        popupWindow.setContentView(initViews());


    }

    private View initViews() {
        View view = LayoutInflater.from(context).inflate(R.layout.select_remind_way_popup_window, null);
//        震动
        remind_way1 = view.findViewById(R.id.tv_drug_way_1);
//        铃声
        remind_way2 = view.findViewById(R.id.tv_drug_way_2);
        remind_way1.setOnClickListener(this);
        remind_way2.setOnClickListener(this);
        return view;
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.tv_drug_way_1:
                selectRemindWayPopupOnClickListener.obtainMessage(0);
                break;
            case R.id.tv_drug_way_2:
                selectRemindWayPopupOnClickListener.obtainMessage(1);
                break;
            default:
                break;
        }
        dismiss();

    }

    public interface SelectRemindWayPopupOnClickListener{
        void obtainMessage(int flag);
    }
    public void setSelectRemindWayPopupListener(SelectRemindWayPopupOnClickListener l){
        this.selectRemindWayPopupOnClickListener = l;
    }
    public void dismiss(){
        if(popupWindow != null && popupWindow.isShowing())
            popupWindow.dismiss();
    }
    public void showPopup(View rootView){
//        第一个参数是要放到的view,第二个参数是位置， 第三，第四是偏移量
        popupWindow.showAtLocation(rootView, Gravity.BOTTOM,0,0);
    }
}
